/**
 * 
 */
package com.hexacta.hrs.services.familiarrelationship.impl;

import java.util.Collection;

import org.vectrics.employee.Employee;

import com.hexacta.hrs.familiarrelationship.FamiliarRelationShipTypes;
import com.hexacta.hrs.familiarrelationship.FamiliarRelationship;
import com.hexacta.hrs.repositories.impl.FamiliarRelationshipRecordObjectRepository;
import com.hexacta.hrs.services.familiarrelationship.FamiliarRelationshipService;

/**
 * Implementacion del Servicio Familiar Relationship.
 * @author mfunes
 *
 */
 class FamiliarRelationshipServiceImpl implements	FamiliarRelationshipService {

	private FamiliarRelationshipRecordObjectRepository familiarRelationshipGenericRepository;
	
	public void setFamiliarRelationshipGenericRepository(FamiliarRelationshipRecordObjectRepository familiarRelationshipGenericRepository) {
		this.familiarRelationshipGenericRepository = familiarRelationshipGenericRepository;
	}

	/** {@inheritDoc} */
	public FamiliarRelationship createNew() {
		return new FamiliarRelationship();
	}

	/** {@inheritDoc} */
	public void delete(FamiliarRelationship recordObject) {
		this.familiarRelationshipGenericRepository.delete(recordObject);
	}

	/** {@inheritDoc} */
	public void save(FamiliarRelationship recordObject) {
		this.familiarRelationshipGenericRepository.save(recordObject);
	}

	/** {@inheritDoc} */
	public Collection<FamiliarRelationship> searchByCriteria(FamiliarRelationship criteria) {
		return this.familiarRelationshipGenericRepository.matching(criteria);
	}

	/** {@inheritDoc} */
	public FamiliarRelationship searchById(long id) {
		return this.familiarRelationshipGenericRepository.forId(id);
	}

	/** {@inheritDoc} */
	public boolean hasSpouse(Employee employee) {
		FamiliarRelationship criteria = this.createNew();
		criteria.setEmployee(employee);
		criteria.setFamiliarRelationshipType(FamiliarRelationShipTypes.CONYUGE);
		Collection<FamiliarRelationship> result = this.familiarRelationshipGenericRepository.matching(criteria);
		if(result.isEmpty())
			return false;
		return true;
	}

}
